package com.content.view.Share.Player
{
	import com.clerkq.FP.FlipPage;
	import com.clerkq.FlvPlayer.FlvPlayer;
	import com.clerkq.FlvPlayer.VideoPlayer;
	import com.content.model.LoadedAssets.SkinProxy;
	import com.content.model.OnlineRes.OnlineResVO_Book;
	import com.content.view.Component.Button.TextButtonColor;
	import com.library.core.IDisposable;
	import com.library.core.UIObject;
	import com.library.utils.Geometry;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	
	import gs.TweenLite;
	
	public class BookPlayer extends UIObject
	{
		private const FLIP_ANGLE:Number = 5;
		
		public static const NAME:String							= 'BookPlayer';
		public static const BUTTON_CLOSE:String						= NAME + "-" + 'ButtonClose';
		
		private var _sWidth:int;
		private var _sHeight:int;
		
		private var _stage:Stage;
		private var _container:Sprite;
		private var _bg:Shape;
		private var _vo:OnlineResVO_Book;
		private var _btnClose:TextButtonColor;
		
		private var _fp:FlipPage;
			
		public function BookPlayer(){
			_container = new Sprite()
			
			_bg = new Shape();
			_container.addChild(_bg);
			
			
		}
		public function Init(stage:Stage):void{
			_stage = stage;
			
			_fp = new FlipPage(_stage);
			_container.addChild(_fp);
			
			_fp.resetModel();
			_fp.setSize(425, 578);
			_fp.hasCover = true;
			_fp.setAccRatio(0.6,0.55,0.4,0.4);
			_fp.setFlipArea(true, true, true, 50, 50, 25);
			_fp.setVisiblePages(2,2,4);
			
			var itemPath:String;
			_fp.addPage("1", "assets/res/book/1/1/double.jpg");
			_fp.addPage("2", "assets/res/book/1/2/double.jpg");
			_fp.addPage("3", "assets/res/book/1/3/double.jpg");
			_fp.addPage("4", "assets/res/book/1/4/double.jpg");
			_fp.addPage("5", "assets/res/book/1/5/double.jpg");
			_fp.addPage("6", "assets/res/book/1/6/double.jpg");
			_fp.addPage("7", "assets/res/book/1/7/double.jpg");
			_fp.addPage("8", "assets/res/book/1/8/double.jpg");
			_fp.addPage("9", "assets/res/book/1/9/double.jpg");
			_fp.addPage("10", "assets/res/book/1/10/double.jpg");
			_fp.addPage("11", "assets/res/book/1/11/double.jpg");
			_fp.addPage("12", "assets/res/book/1/12/double.jpg");
			_fp.flipToPage(0, FLIP_ANGLE, 20);
			
			_btnClose = new TextButtonColor("退出播放",	0x3b6893, 0xebebeb, 0xffffff, 0x000000, 8);
			_container.addChild(_btnClose);
			_btnClose.id = BUTTON_CLOSE;
		}
		
		public function Play(vo:OnlineResVO_Book):void
		{		
			_stage.addChild(_container);
			
			_fp.flipToPage(0, FLIP_ANGLE, 20);
			
//			_player.play("assets/res/video/demo.flv");		
			
			_stage.addEventListener(MouseEvent.CLICK, OnClick);
			
			_container.visible = false;
			_container.alpha = 0;
			TweenLite.to( _container, 0.5, { autoAlpha: 1 } );
			
			SetLayout(_sWidth, _sHeight);
		}
		
		private function Destory():void
		{
			if(_stage != null){
				_stage.removeEventListener(MouseEvent.CLICK, OnClick);
				_stage.removeChild(_container);
			}
		}
		
		public function SetLayout(sWidth:int, sHeight:int):void{
			_sWidth = sWidth;
			_sHeight = sHeight;
			
			if(_stage == null || !_stage.contains(_container)) return;
			
			_bg.graphics.clear();
			_bg.graphics.beginFill(0x000000, 0.6);
			_bg.graphics.drawRect(0,0,sWidth, sHeight);
			
			_fp.x = int(sWidth/2);
			_fp.y = int((sHeight- 578)/2);
			
			_btnClose.x = int((sWidth - _btnClose.width)/2);
			_btnClose.y = _fp.y + 578 - 20;
		}
		
		/**
		 * Event Handler 
		 */
		private function OnClick(evt:MouseEvent):void{
			if(evt.target is TextButtonColor){
				var txtBtn:TextButtonColor = evt.target as TextButtonColor;
				switch(txtBtn.id){
					case BUTTON_CLOSE:
						Destory();
						break;
				}
			}
		}
		
		/*// Singleton
		private static var _instance:PdfPlayer;
		public static function get instance():PdfPlayer {
			if ( _instance == null ) _instance = new PdfPlayer( );
			return _instance as PdfPlayer;
		}*/
	}
}